﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Microsoft.Practices.Unity;
using Zeus.IOC.Unity;
using Zeus.Thunder.Web.Download;
using Zeus.Thunder.Web.Legacy;

namespace Zeus.Thunder.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        #region Members

        //private static IUnityContainer _container;

        #endregion

        #region Properties

        /// <summary>
        /// The Unity container for the current application
        /// </summary>
        //public static IUnityContainer Container
        //{
        //    get
        //    {
        //        return _container;
        //    }
        //}

        #endregion

        #region IContainerAccessor Members

        /// <summary>
        /// Returns the Unity container of the application 
        /// </summary>
        //IUnityContainer IContainerAccessor.Container
        //{
        //    get { return Container; }
        //}

        #endregion

        #region Application Events
        
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //unity code
            //InitContainer();
            //ControllerBuilder.Current.SetControllerFactory(typeof(UnityControllerFactory));
        }

        //protected void Application_End(object sender, EventArgs e)
        //{
        //    CleanUp();
        //}
        
        #endregion

        #region Methods

        /*
        private static void InitContainer()
        {
            if (_container == null)
            {
                _container = new UnityContainer();
            }

            // Register the relevant types for the 
            // container here through classes or configuration
            _container.RegisterType<IPurchasableHelper, PurchasableDownloadHelper>();
            //_container.RegisterType<IFileDownload, ExcelDownload>("ExcelDownload");
            //_container.RegisterType<IFileDownload, CsvDownload>("CsvDownload");
        }

        private static void CleanUp()
        {
            if (Container != null)
            {
                Container.Dispose();
            }
        }
        */

        #endregion
    }
}